package com.dzsw.thread;

/**
 * @author sunz
 * @version 1.0
 * @CreateTime 2021-04-20-13:32
 */
public class SyncThread {

    public static void main(String[] args) throws Exception {
        AddThread add = new AddThread();
        AddThread dec = new AddThread();
        add.start();
        dec.start();
        add.join();
        dec.join();
        System.out.println(Counter.count);
    }
}

class Counter {
    public static int count = 0;
}

class AddThread extends Thread {
    public void run() {
        for (int i = 0; i < 10000; i++) {
            Counter.count += 1;
        }
    }
}

class DecThread extends Thread {
    public void run() {
        for (int i = 0; i < 10000; i++) {
            Counter.count -= 1;
        }
    }
}